#!/usr/bin/lua

-- dependencies:
---- penlight

local args = require[[pl.lapp]][[
scatter a single specification into database tables,
database types, database functions, a Java backend,
an HTML frontend, a JavaScript AJAX API,
and a beautiful database document written in HTML.

    -s, --sql (default "")      sql output filename
    <input> (default stdin)     specification file
]]

local pp = require[[pl.pretty]].dump
pp(args)

local scatter = require[[scatter]]
local src = args.input:read('a')
local result = scatter(src)
pp(result)

for k,v in pairs(result) do
    if args[k] ~= nil and args[k] ~= "" then
        local f,err = io.open(args[k], 'w')
        if f == nil then error(err) end
        f,err = f:write(v)
        if f == nil then error(err) end
        f:close()
    end
end


